package com.zhugang.week06;

import java.util.ArrayList;
import java.util.List;

/**
 * @program algorithms
 * @description: postorderN
 * @author: chanzhugang
 * @create: 2022/07/15 14:47
 */
public class PostorderN {

    /**
     * 590 N叉树的后序遍历
     *
     * @param root
     * @return
     */
    List<Integer> list = new ArrayList<>();

    public List<Integer> postorder(Node root) {
        postorder_n(root);
        return list;
    }

    private void postorder_n(Node root) {
        if (root == null) {
            return;
        }
        for (int i = 0; i < root.children.size(); i++) {
            postorder_n(root.children.get(i));
        }
        list.add(root.val);
    }

    class Node {
        public int val;
        public List<Node> children;

        public Node() {
        }

        public Node(int _val) {
            val = _val;
        }

        public Node(int _val, List<Node> _children) {
            val = _val;
            children = _children;
        }
    }

    ;
}